import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
// 静态路由
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  // {
  //   path: "/",
  //   component: Layout,
  //   redirect: "/homePage"
  // },

  {
    path: "/",
    component: Layout,
    redirect: "/homePage",
    children: [
      {
        path: "/homePage",
        name: "首页",
        component: () => import("@/views/home"),
        meta: { title: "首页", icon: "form" }
      }
    ]
  }

  // {
  //   path: "/shellList",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "shell",
  //       name: "shell",
  //       component: () => import("@/views/shell/shellList"),
  //       meta: { title: "终端管理", icon: "form" }
  //     }
  //   ]
  // },
  // 404 page must be placed at the end !!!
  // { path: "*", redirect: "/404", hidden: true }
];
// 异步路由
export const asyncRoutes = [
  {
    path: "/integration",
    name: "设备集成",
    redirect: "/deviceList",
    component: Layout,
    meta: { title: "设备集成", icon: "form" },
    children: [
      {
        path: "/deviceList",
        // name: "device",
        component: () => import("@/views/s.vue"),
        meta: { title: "设备列表", icon: "form" },
        children: [
          {
            name: "device",
            path: "",
            component: () => import("@/views/integration/deviceList")
            // meta: { title: "设备列表", icon: "form" },
          },
          {
            path: "deviceInfo",
            name: "deviceInfo",
            component: () => import("@/views/integration/deviceInfo"),
            meta: { title: "设备详情", icon: "form" },
            hidden: true
          }
        ]
      },
      {
        path: "/groupList",
        name: "group",
        component: () => import("@/views/integration/groupList"),
        meta: { title: "设备分组", icon: "form" }
      },
      // {
      //   path: "/deviceInfo",
      //   name: "deviceInfo",
      //   component: () => import("@/views/integration/deviceInfo"),
      //   meta: { title: "设备详情", icon: "form" },
      //   hidden: true
      // },
      {
        path: "/seeDeviceListStaus",
        name: "seeDeviceListStaus",
        component: () => import("@/views/integration/seeDeviceListStaus"),
        meta: { title: "设备状态列表", icon: "form" },
        hidden: true
      },
      {
        path: "/groupDetails",
        name: "分组详情",
        component: () => import("@/views/integration/groupDetails"),
        meta: { title: "分组详情", icon: "form" },
        hidden: true
      }
    ]
  },

  {
    path: "/fileList",
    component: Layout,
    name: "设备升级",
    authCode: "analysisSummary",
    redirect: "/fileCenter",
    meta: {
      title: "设备升级",
      icon: "form"
    },
    children: [
      {
        path: "/fileCenter",
        name: "group",
        component: () => import("@/views/upgrade/fileCenter"),
        meta: { title: "文件中心", icon: "form" }
      },
      {
        path: "/taskList",
        name: "taskList",
        component: () => import("@/views/upgrade/taskList"),
        meta: { title: "任务列表", icon: "form" }
      },
      {
        path: "/taskDispatchAdd",
        name: "taskDispatchAdd",
        component: () => import("@/views/upgrade/taskDispatchAdd"),
        meta: { title: "任务新增", icon: "form" },
        hidden: true
      },
      {
        path: "/taskDispatchEdit",
        name: "taskDispatchEdit",
        component: () => import("@/views/upgrade/taskDispatchEdit"),
        meta: { title: "任务编辑", icon: "form" },
        hidden: true
      },
      {
        path: "/taskOverview",
        name: "taskOverview",
        component: () => import("@/views/upgrade/taskOverview"),
        meta: { title: "任务概况", icon: "form" },
        hidden: true
      },
      {
        path: "/taskDeviceList",
        name: "taskDeviceList",
        component: () => import("@/views/upgrade/taskDeviceList"),
        meta: { title: "设备升级清单", icon: "form" },
        hidden: true
      },
      {
        path: "/statistics",
        name: "statistics",
        component: () => import("@/views/upgrade/statistics"),
        meta: { title: "升级统计", icon: "form" }
      },
      {
        path: "/passwordUpdate",
        name: "passwordUpdate",
        component: () => import("@/views/upgrade/passwordUpdate"),
        meta: { title: "密码修改", icon: "form" }
      }
    ]
  },
  {
    path: "/systemLog",
    component: Layout,
    alwaysShow: true,
    redirect: "/operationLog",
    meta: {
      title: "系统日志",
      icon: "form"
    },
    children: [
      {
        path: "/operationLog",
        name: "operationLog",
        component: () => import("@/views/systemLog/operationLog"),
        meta: { title: "设备操作日志", icon: "form" }
      },
      {
        path: "/sysoperationLog",
        name: "sysoperationLog",
        component: () => import("@/views/systemLog/sysoperationLog"),
        meta: { title: "系统操作日志", icon: "form" }
      },
      {
        path: "/deviceNoticeLog",
        name: "deviceNoticeLog",
        component: () => import("@/views/systemLog/deviceNoticeLog"),
        meta: { title: "设备上下线日志", icon: "form" }
      },
      {
        path: "/loginLog",
        name: "loginLog",
        component: () => import("@/views/systemLog/loginLog"),
        meta: { title: "登录日志", icon: "form" }
      }
    ]
  },
  {
    path: "/sys",
    component: Layout,
    name: "系统管理1",
    authCode: "analysisSummary",
    redirect: "/tenant",
    meta: {
      title: "系统管理",
      icon: "form"
    },
    children: [
      {
        path: "/tenant",
        name: "tenant",
        component: () => import("@/views/sys/tenant"),
        meta: { title: "租户管理", icon: "form" }
      },
      {
        path: "/user",
        name: "user",
        component: () => import("@/views/sys/userList"),
        meta: { title: "用户管理", icon: "form" }
      },
      {
        path: "/role",
        name: "role",
        component: () => import("@/views/sys/role"),
        meta: { title: "角色管理", icon: "form" }
      },
      {
        path: "/menu",
        name: "menu",
        component: () => import("@/views/sys/menu"),
        meta: { title: "菜单管理", icon: "form" }
      }
    ]
  },
  {
    path: "/baseConfig",
    component: Layout,
    children: [
      {
        path: "/baseConfig",
        name: "user",
        component: () => import("@/views/link/baseConfig"),
        meta: { title: "基础配置", icon: "form" }
      }
    ]
  }
];
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    // routes: constantRoutes.concat(asyncRoutes)
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
